package com.arelikebrothers.demo.kafka.stream;

import com.google.gson.Gson;
import org.apache.kafka.common.serialization.Serializer;

import java.util.Map;

/**
 * Created by lennon on 16/07/2017.
 */
public class JsonSerializer<T> implements Serializer<T>{

    private Gson gson = new Gson();

    @Override
    public void configure(Map<String, ?> map, boolean b) {

    }

    @Override
    public byte[] serialize(String s, T t) {
        if(t == null)
        {
            return null;
        }

        String json = gson.toJson(t);
        return json.getBytes();
    }

    @Override
    public void close() {

    }
}
